package it.poste.il.compensatore.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Classe che modella l'entita' MessageStatus.
 */
@Entity
@Table(name="messagestatus")
public class MessageStatus extends BaseEntity {

	private static final long serialVersionUID = 1302661337791208655L;

	private String description;

	@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="statusId", targetEntity=Message.class)
	private Message message;
	
	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	/**
	 * Costruttore di default del MessageStatus.
	 * Inizializza l'entita' con la descrizione vuota.
	 * POST: getDescription() == null
	 */
	public MessageStatus(){
		
	}
	
	/**
	 * Metodo accessor della proprieta' description.
	 * Restituisce il valore corrente di description
	 * @return valore della proprieta' description;
	 */
	public String getDescription() {
		return description;
	}
	
	/**
	 * Metodo mutator della proprieta' description.
	 * Assegna un nuovo valore alla proprieta' description.
	 * POST: setDescription().equals(description);
	 * @param description nuovo valore da assegnare a description.
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		result = prime * result + ((message == null) ? 0 : message.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MessageStatus other = (MessageStatus) obj;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		if (message == null) {
			if (other.message != null)
				return false;
		} else if (!message.equals(other.message))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.getClass().getName() + " [id=" + getId() + ", description="
				+ description + "]";
	}

}
